<template>
	<view>
		<view style="margin-left: 50rpx;position: fixed;top: 10rpx;left: 50rpx;z-index: 1212;">
			<input  style="width: 600rpx;height: 65rpx;background: #FFFFFF;border: 1rpx solid #EE7B30;border-radius: 30rpx;box-sizing: border-box;padding: 9rpx 20rpx;font-size: 30rpx;" placeholder="请输入机构名字" v-model="name" @change="sousuo"/>
			<view style="position: fixed;left: 530rpx;top:10rpx;z-index: 12121212;width: 200rpx;height: 65rpx;text-align: center;" @tap="sousuo">
				<image :src="sou" mode="" style="width: 30.34rpx;height: 35.58rpx;vertical-align: middle;"></image>
			</view>
		</view>
		<view style="position: fixed;top: 100rpx;height: 500rpx;width: 750rpx;line-height: 500rpx;text-align: center;letter-spacing: 3rpx;color: #FF7300;font-weight: bold;font-size: 50rpx;" v-if="list_jigou_huan.length == 0" class="suofang">
			教付保让学习更美好
		</view>
		<view style="position: fixed;top:85rpx;z-index: 121212;">
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" style="height: 1250rpx;width: 750rpx;" :lower-threshold="lower_threshold" refresher-enabled="true" :refresher-triggered="triggered" @refresherrefresh="onRefresh" :refresher-threshold="100" @refresherpulling="pulling" refresher-background="#FF7300">
				<view class="tuijiankecheng">
					<view class="tuijiankecheng_" v-for="(itme,index) in list_jigou_huan" :key="index">
						<view style="display: flex;" @tap.stop="xiangqing(itme)">
							<view style="position: relative;">
								<image :src="itme.mechanism_logo" style="width: 195.02rpx;height: 195.02rpx;border-radius: 20rpx;border: #D6D6D6 0.09rpx solid;vertical-align: top;margin: 0;"></image>
								<view style="position: absolute;top: 0;left: 0;z-index: 12121;min-width: 70.7rpx;height: 35rpx;text-align: center;line-height: 35rpx;color: #FFFFFF;font-size: 20rpx;border-radius: 20rpx 0 20rpx 0 ;background: #FF3D3D;padding: 0 10rpx;">{{itme.categories_child}}</view>
							</view>
							<view style="margin-left: 24.153rpx;width: 380rpx;box-sizing: border-box;padding-right: 20rpx;"> 
								<view style="font-size: 33rpx;color: #414141;font-weight: bold;white-space:nowrap; overflow:hidden; text-overflow:ellipsis;width: 380rpx;">{{itme.mechanism_name}}</view>
								<view style="height: 30.8rpx;margin: 15rpx 0 15rpx 0;display: flex;align-items: center;">
									<view>
										<van-rate  :value="itme.avg_rating"></van-rate>
									</view>
									<!-- <view style="font-size: 25.717rpx;font-weight: bold;color: #474747;white-space:wrap;">
										<text >{{itme.juli}}</text>
										<text>km</text>
									</view> -->
								</view>
								<view style="font-size: 25.95rpx;color: #BEBEBE;width:inherit;white-space:wrap;display:block;   white-space:normal; ">
								   {{itme.mechanism_addr}}
								</view>
							</view>
						</view>
						<view v-if="itme.bealue" style="margin-top: 30rpx;">
							<view v-for="(itmes,indexs) in itme.tujian" :key="indexs" @tap="gokechengxiang(itmes,itme)">
								<view style="display: flex;align-items: center;justify-content: space-between;height: 30rpx;">
									<view style="display: flex;align-items: center;height: 40rpx;">
										<view style="width: 120rpx;height: 40rpx;background: #FF492B;color: #FFFFFF;font-size: 20rpx;line-height: 40rpx;text-align: center;border-radius: 15rpx;">热门推荐</view>
										<view style="font-size: 25rpx;font-weight: bold;">{{itmes.biao}}</view>
									</view>
									<view style="color: #F65454;height: 40rpx;position: relative;top: -10rpx;">
										<text style="font-size: 15rpx;">￥</text>
										<text style="font-size: 28rpx;font-weight: bold;">{{itmes.original_price}}</text>
										<text style="font-size: 22rpx;">/节</text>
									</view>
								</view>
								<view style="height: 2rpx;width: 100%;background: #F5F5F5;margin: 30rpx 0;" v-if="itmes.shuzu_biao"></view>
							</view>
							<view style="width: 100%;text-align: center;font-size: 28rpx;color: #C7C7C7;margin-top: 30rpx;" @tap="gengduoke(itme)">查看更多数据
								<image :src="imgg" mode="" style="width: 16.08rpx;height: 20.52rpx;margin-left: 12.67rpx;vertical-align: middle;"></image>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	export default {
		data(){
			return {
				sou: "http://img.curiousmore.com/971276",
				name: "",
				list_jigou_huan: [],
				triggered: false,
				xinjifou_ke: [],
				currentPage: 1,
				res_: 1
			}
		},
		methods:{
			gokechengxiang(itme,itmes){
				uni.navigateTo({
					url: '/pages/World/classChannel/classChannel?curriculumId=' + itme.id
				})
			},
			gengduoke(itme){
				uni.navigateTo({
					url: "/pages/Friend/groupTalk/groupTalk?id=" + itme.id
				})
			},
			
			xiangqing(itt){
				uni.navigateTo({
					url:'/pages/Meet/jigouxiangqing/jigouxiangqing?id=' +  itt.id
				})
			},
			sousuo(){
				this.list_jigou_huan = []
				this.xinjifou_ke = []
				if(this.name == ""){
					uni.showToast({
						title: "请输入要搜索的机构名称",
						icon: "none"
					})
				}else {
					this.xinjigou()
				}
			},
			async xinjigou(){
				let _this = this
				const res = await _this.$myRequest({
					url:'/mastermechanism/queryMechanismByType',
					method:"GET",
					data:{
						mechanism_name: this.name,
						currentPage: this.currentPage,
						pageSize: 10,
						sortName: "is_recommend",
						type: "teach_paypal"
					}
				})
				let data = {
					title:"暂无课程",
					course_num:"",
					discount_amout:"",
					amout:""
				}
				if(res.data.length == 0){
					_this.res_ = 2
				}
				res.data.forEach((itme) => {
					if(itme.map.masterSetPriceEntity != null){
						if(itme.map.masterSetPriceEntity.length > 2){
							itme.tujian =  itme.map.masterSetPriceEntity.slice(0,2)
						}else{
							itme.tujian =  itme.map.masterSetPriceEntity.slice(0,itme.map.masterSetPriceEntity.length)
						}
					}
					if(itme.map.masterSetPriceEntity != null && itme.map.masterSetPriceEntity.length != 0){
						itme.bealue = true
						itme.map.masterSetPriceEntity.forEach((shu,indexss) => {
							shu.biao = "【" + shu.course_num + "节】" + shu.title
							if(indexss == 0){
								shu.shuzu_biao = true
							}else{
								shu.shuzu_biao = false
							}
						})
					}else if(itme.map.masterSetPriceEntity == null || itme.map.masterSetPriceEntity.length == 0){
						itme.bealue = false
					}
				})
				let a = []
				let b = res.data
				b.forEach((itme,index) => {
					if(itme.map.masterSetPriceEntity.length == 0){
						itme.map.masterSetPriceEntity.push(data)
						itme.dis = false
					}else{
						itme.dis = true
					}
					itme.juli = _this.getDistance(itme.latitude,itme.longitude,_this.weidu,_this.jingdu).toFixed(1)
				})
				if( _this.xinjifou_ke.length == 0){
					 _this.xinjifou_ke = b
				}else if(  _this.xinjifou_ke.length > 0 && b.length > 0){
					_this.xinjifou_ke = _this.xinjifou_ke.concat(b)
				}
				_this.list_jigou_huan = _this.xinjifou_ke
				_this.triggered= false
			},
			rad(d) {
				return d * Math.PI / 180.0; 
			},
			getDistance(lat1, lng1, lat2, lng2) {
				let me = this
				var radLat1 = me.rad(lat1);
				var radLat2 = me.rad(lat2);
				var a = radLat1 - radLat2;
				var b = me.rad(lng1) - me.rad(lng2);
				var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
					Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
				s = s * 6378.137; // EARTH_RADIUS;
				s = Math.round(s * 10000) / 10000; //输出为公里
				var distance = s;
				var distance_str = "";
				if (parseInt(distance) >= 1) {
					distance_str = distance.toFixed(1) + "km";
				} else {
					distance_str = distance * 1000 + "m";
				}
				return s;
			},
			onRefresh(){
				this.currentPage = 1
				this.triggered= true
				setTimeout(() => {
					this.triggered= false
				},2000)
			},
			lower(){
				if(this.res_ == 1){
					this.currentPage++
					this.xinjigou()
				}else{
					uni.showToast({
						title: "暂无数据",
						icon: "none"
					})
				}
			}
		},
		onLoad() {
			
		}
	}
</script>
<style lang="scss" scoped>
	.tuijiankecheng{
		width: 750rpx;
		background:#FFFFFF;
		margin-top:6.03rpx;
		.tuijiankecheng_{
			box-sizing: border-box;
			padding: 21.146rpx 52.548rpx 32rpx 55.57rpx ;
			white-space: nowrap;
			text-overflow: ellipsis;
			overflow: hidden;
			.tuijian_xia{
				margin-top: 47.112rpx;
			}
		}
	}
	.suofang{
		animation:mymove  10s linear infinite;
		-webkit-animation:mymove 10s ease 1 infinite; /*Safari and Chrome*/
	}
	@keyframes mymove{
		0%{
		  /*开始为原始大小*/
		  color: #8B4513;
		}
		50%{
			color: #FF7300;
		}
		100%{
			color: #8B4513;
		}
	}
</style>